<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('参股基金')" prop="dealId">
            <el-select v-model="form.dealId" :disabled="form.id" filterable clearable :placeholder="$t('请选择')">
              <el-option
                v-for="item in dealNameOptions"
                :key="item.id"
                :label="item.label"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('发生时间')" prop="occurrenceTime">
            <el-date-picker
              v-model="form.occurrenceTime"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('发生时间')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('业务介绍')" prop="businessDescription">
            <EditorTxt v-if="!loading" ref="editorText" v-model="form.businessDescription" :height="300" :placeholder="$t('业务介绍')" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('公司主要发展和近期计划')" prop="recentDevel">
            <EditorTxt v-if="!loading" ref="editorText" v-model="form.recentDevel" :height="300" :placeholder="$t('公司主要发展和近期计划')" />
          </el-form-item>
        </el-col>
      </el-row>
      <FileTable :list.sync="form.fileList" data-type="company_project_recent_devel" :business-id="form.dealId" />
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="company:projectRecentDevel" />
    </div>
  </div>
</template>

<script>
import { saveCompanyProjectRecentDevel, getCompanyProjectRecentDevel } from '@/api/sass/jswt/projectRecentDevel/companyProjectRecentDevel'
import { lisDealName } from '@/api/bf/investGroup/bfInvestGroup'
import EditorTxt from '@/components/Tinymce'
export default {
  components: {
    EditorTxt
  },
  data() {
    return {
      // 表单参数
      form: {
        fileList: []
      },
      // 参股基金下拉框
      dealNameOptions: [],
      // 遮罩层
      loading: true,
      // 查询公司指标参数
      queryParams: {
        indirectDealId: this.companyId || this.$route.query.companyId,
        source: 'BF_PORTFOLIO'
      },
      // 表单校验
      rules: {
        dealId: [
          { required: true, message: this.$t('必填信息'), trigger: 'change' }
        ],
        occurrenceTime: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    // 获取所有关联项目
    lisDealName(this.queryParams).then(response => {
      this.dealNameOptions = response.rows
    })
  },
  methods: {
    // 初始化数据
    init(data) {
      this.loading = true
      if (data != null && data.id !== undefined) {
        getCompanyProjectRecentDevel(data.id).then(response => {
          this.form = response.data
          this.loading = false
        }).catch(() => {
          this.loading = false
        })
      } else {
        this.reset()
        this.loading = false
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        companyId: this.$route.query.companyId,
        dealId: this.$route.query.dealId,
        occurrenceTime: undefined,
        businessDescription: undefined,
        recentDevel: undefined,
        remark: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    },
    // 取消按钮
    cancel() {
      this.$parent.$parent.formOpen = false
      this.$parent.$parent.reset()
    },
    // 关闭form页面
    closeForm() {
      // 关闭form页面遮罩层
      this.loading = false
      // 关闭form页面
      if (this.$parent.$parent.formOpen !== undefined) {
        this.$parent.$parent.formOpen = false
      }
      // 刷新list页面
      if (this.$parent.$parent.getList !== undefined) {
        this.$parent.$parent.getList()
      }
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.loading = true
          saveCompanyProjectRecentDevel(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess(this.$t('保存成功'))
              this.closeForm()
            } else {
              this.msgError(response.msg)
            }
            this.loading = false
          })
        } else {
          this.locationError(document)
        }
      }).catch(() => {
        this.loading = false
      })
    }
  }
}
</script>
